package com.cz.basetool.ui_work.util.et_bind;


import android.util.Pair;

import com.cz.basetool.ui_work.util.txt.CZ_TextUtil;
import com.cz.basetool.ui_work.util.txt.RegularUtil;
import com.cz.basetool.ui_work.util.et_bind.base.BaseEditTextValidator;

/**
 * Created by 陈章 on 2017/4/12 0012.
 * func:
 * 证件号码校验器
 * 要求：字母大写
 */
public class CertificateNumberValidator extends BaseEditTextValidator {
    public CertificateNumberValidator() {
    }

    public CertificateNumberValidator(OnValidatorResultObserver validatorResultObserver) {
        super(validatorResultObserver);
    }

    @Override
    public Pair validate(String txt) {
        if(CZ_TextUtil.is_null_or_empty(txt)){
            return getEmptyTipPair();
        }
        boolean check = RegularUtil.check(txt, "^(11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65)\\d{15}(\\d{1}|X)$");
        if(check == true) return  getRightPair();


        if(CZ_TextUtil.hasLowerLitter(txt)){
            return getErrorPair("证件号码不可包含小写字母");
        }

        boolean identificationCard = RegularUtil.isIdentificationCard(txt);
        if(identificationCard){
            return getRightPair();
        }else{
            return getErrorPair("证件号码不合法");
        }

    }
}
